package org.bingo.security.core.validate.code;

import lombok.Data;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 验证码信息封装类
 */
@Data
public class ValidateCode implements Serializable {
    private static final long serialVersionUID = 7900322444507604286L;

    //验证码
    private String code;

    // 过期时间
    private LocalDateTime expireTime;

    /**
     * 构造方法
     * @param code
     * @param expireIn 多少秒后过期
     */
    public ValidateCode(String code, int expireIn) {
        this.code = code;
        this.expireTime = LocalDateTime.now().plusSeconds(expireIn);
    }

    public ValidateCode(String code, LocalDateTime expireTime) {
        this.code = code;
        this.expireTime = expireTime;
    }

    /**
     * 是否过期，如果当前时间大于过期时间则为已过期
     * @return
     */
    public boolean isExpired() {
        return LocalDateTime.now().isAfter(expireTime);
    }
}
